<template>
  <div class="net-img">
    <el-image class="img" :style="{width: size[0] + 'px', height: size[1] + 'px'}"
              v-for="img in fileList" :src="img"
              :preview-src-list="fileList" fit="contain"
              v-bind="$attrs">
    </el-image>
  </div>
</template>

<script>

import {getFile} from "@/api/file";

export default {
  name: 'ImgThumbnail',
  props: {
    fileId: {
      type: String,
      default: ''
    },
    size: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      fileList: []
    }
  },
  computed: {
    previewList(){},
  },
  watch: {
    fileId(to) {
      if(to) {
        this.getFile();
      }
    },
  },
  created() {
  },
  mounted() {
    this.getFile();
  },
  methods: {
    getFile(){
      if(!this.fileId) return;
      let tmp = this.fileId.split(',');
      this.fileList = []
      tmp.forEach((item, i) => {
        getFile(item).then(res => {
          /*if( res.fileUrl.indexOf("?") !== -1 ){
            res.fileUrlNew = res.fileUrl + '&rename=' + res.name
          }else{
            res.fileUrlNew = res.fileUrl + '?rename=' + res.name
          }*/
          this.$set(this.fileList, i, this.$store.state.settings.basePath + res.fileUrl)
        })
      })
    },
  }
}
</script>

<style lang="scss" scoped>
  .img {
    border: 1px solid #E3E3E3;
    border-radius: 4px;
    margin-right: 16px;
    &:last-child{
      margin-right: 0;
    }
  }
</style>
